#ifndef SERIALPORTMANAGE_H
#define SERIALPORTMANAGE_H

#include <QObject>
#include <QPair>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QFile>
#include <QDebug>

struct SerialConfig {
    int id;
    int device_id;
    QString name;
    QString portName;
    qint32 baudRate;
    QSerialPort::DataBits dataBits;
    QSerialPort::Parity parity;
    QSerialPort::StopBits stopBits;
    QSerialPort::FlowControl flowControl;
};

class SerialPortManage : public QObject
{
    Q_OBJECT
public:
    explicit SerialPortManage(QObject *parent = nullptr);
    ~SerialPortManage();
    void initialization();
    bool getOpendFlag();
    void setOpendFlag(bool);
    QSerialPort *getSerialPtr();

    QList<QPair<QString,QSerialPort::BaudRate>> baudRates{
        {"1200",QSerialPort::Baud1200},
        {"2400",QSerialPort::Baud2400},
        {"4800",QSerialPort::Baud4800},
        {"9600",QSerialPort::Baud9600},
        {"19200",QSerialPort::Baud19200},
        {"38400",QSerialPort::Baud38400},
        {"57600",QSerialPort::Baud57600},
        {"115200",QSerialPort::Baud115200}
    };

    QList<QPair<QString,QSerialPort::DataBits>> dataBits{
        {"8",QSerialPort::DataBits::Data8},
        {"7",QSerialPort::DataBits::Data7},
        {"6",QSerialPort::DataBits::Data6},
        {"5",QSerialPort::DataBits::Data5},
    };
    QList<QPair<QString,QSerialPort::Parity>> parityBits{
        {"NONE",QSerialPort::Parity::NoParity},
        {"ODD",QSerialPort::Parity::OddParity},
        {"EVEN",QSerialPort::Parity::EvenParity},
        {"MARK",QSerialPort::Parity::MarkParity},
        {"SPACE",QSerialPort::Parity::SpaceParity}
    };
    QList<QPair<QString,QSerialPort::StopBits>> stopBits{
        {"1",QSerialPort::StopBits::OneStop},
        {"1.5",QSerialPort::StopBits::OneAndHalfStop},
        {"2",QSerialPort::StopBits::TwoStop},
    };

private:
    bool m_isOpend;
    QSerialPort *m_pSerialPort;

signals:

};

#endif // SERIALPORTMANAGE_H
